<!-- 存放辅助函数 -->

<?php
function basePath($path = ''){
    // 将当前目录与path路径相拼接
    return __DIR__ . '/' .$path;
}

function loadPartial($name,$data = []){
    $partialPath = basePath("App/views/partials/{$name}.php");
    
    if (file_exists($partialPath)) {
        # code...
        extract($data);
        require $partialPath;
    } else {
        # code...
        echo "{$name}视图不存在！";
    }
    
}

function loadView($name,$data = []){
    $viewPath = basePath("App/views/{$name}.view.php");

    if (file_exists($viewPath)) {
        # code...
        extract($data);
        require $viewPath;
    } else {
        # code...
        echo "{$viewPath}视图不存在！";
    }
    
}

function inspect($value){
    echo '<pre>';
    var_dump($value);
    echo '<pre>';
}

function inspectAndDie($value){
    echo '<pre>';
    die(var_dump($value));
    echo '<pre>';
}

function sanitize($dirty){
    return filter_var(trim($dirty), FILTER_SANITIZE_SPECIAL_CHARS);
}

function redirect($url){
    header("Location: {$url}");
    exit;
}

?>